package com.horay.nettydemo.nio.buffer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.unit.DataSize;

import java.nio.ByteBuffer;

/**
 * Put Get Buffer
 *
 * @author heyingcheng
 * @date 2019/11/23 23:16
 */
@Slf4j
public class PutGetBuffer {

    public static void main(String[] args) {
        ByteBuffer byteBuffer = ByteBuffer.allocate(Math.toIntExact(DataSize.ofBytes(64L).toBytes()));
        byteBuffer.put(Byte.MAX_VALUE);
        byteBuffer.putShort(Short.MAX_VALUE);
        byteBuffer.putInt(Integer.MAX_VALUE);
        byteBuffer.putLong(Long.MAX_VALUE);
        byteBuffer.putChar('赫');
        byteBuffer.putFloat(Float.MAX_VALUE);
        byteBuffer.putDouble(Double.MAX_VALUE);

        byteBuffer.flip();
        log.info("byte:[{}]", byteBuffer.get());
        log.info("short:[{}]", byteBuffer.getShort());
        log.info("int:[{}]", byteBuffer.getInt());
        log.info("long:[{}]", byteBuffer.getLong());
        log.info("char:[{}]", byteBuffer.getChar());
        log.info("float:[{}]", byteBuffer.getFloat());
        log.info("double:[{}]", byteBuffer.getDouble());
    }

}
